package pe.bn.WSServiceHost.serHost.model;

import java.util.Vector;
import pe.bn.WSServiceHost.serHost.interactive.WSData;

public class BodyConsultaMultired extends WSData {

	public interface DeudaMultired {
		public void init();
		public void FillBoby(String bodyOutPut) throws Exception;
		public String toString();
		public String getByIndex(int index);
		public String getByTag(String desc);
		public Campo getCampoByIndex(int index);
		public int LongitudTrama();
	}
	
	public class LDeudaMultired extends Vector{
		  public DeudaMultired getDeudaMultired(int i){
		  	return (DeudaMultired)get(i);
		  }
	}
	

public class NivelEndeudamiento extends WSData
	implements DeudaMultired {

	public void init(){
		this.campos = new Campo[7];
		try{
			int num = -1;
			/*Deudas*/
			this.campos[++num]		=	new Campo("IDE-PREST",Campo.RETURN_INIT_BLNK,13);
			this.campos[++num]		=	new Campo("TIP-PREST",Campo.RETURN_INIT_BLNK,35);
			this.campos[++num]		=	new Campo("MTO-CUOTA",Campo.RETURN_INIT_BLNK,17);
			this.campos[++num]		=	new Campo("SDO-PREST",Campo.RETURN_INIT_BLNK,17);
			this.campos[++num]		=	new Campo("CUO-TOTAL",Campo.RETURN_INIT_BLNK,3);
			this.campos[++num]		=	new Campo("CUO-CANCE",Campo.RETURN_INIT_BLNK,3);
			this.campos[++num]		=	new Campo("EST-PREST",Campo.RETURN_INIT_BLNK,10);
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void InputData(
		String idPrestamo				
		,String tipoPrestamo
		,String montoCuota
		,String saldoPrestamo				
		,String cuotaTotal
		,String cuotaCancelada
		,String estadoPrestamo
	) throws Exception {
	
		init();
		int num = -1;
		boolean result = true; 
		result = ValidarCampo(true,this.campos[++num].setString(idPrestamo));
		result = ValidarCampo(result,this.campos[++num].setString(tipoPrestamo));
		result = ValidarCampo(result,this.campos[++num].setString(montoCuota));
		result = ValidarCampo(result,this.campos[++num].setString(saldoPrestamo));
		result = ValidarCampo(result,this.campos[++num].setString(cuotaTotal));
		result = ValidarCampo(result,this.campos[++num].setString(cuotaCancelada));
		result = ValidarCampo(result,this.campos[++num].setString(estadoPrestamo));
		
		if (!result){
			throw new Exception("Error al Dar Formato a la clase:" + this.getClass());
		}
	
	}

	public void FillBoby(String bodyOutPut) throws Exception {
		init();
		super.FillBoby(bodyOutPut);
		}
	}
	

	private LDeudaMultired lDeudaMultired = null;
	
	public void initConsulta(){
		this.campos = new Campo[1];
		try {
			int num = -1;
			this.campos[++num]	= 	new Campo("CTA-AHORROS",Campo.NUM_CODIGO,11);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void initConsultaMultired(){
		
		try {
			initConsulta();
			this.lDeudaMultired = new LDeudaMultired();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}	

	public void InputData(
			String nroCuenta
			,LDeudaMultired lDeudaMultired
			) throws Exception {
		
		initConsulta();
		int num = -1;
		boolean result = true; 
		result = ValidarCampo(true,this.campos[++num].setString(nroCuenta));		
		this.lDeudaMultired = lDeudaMultired;

		if (!result){
			throw new Exception("Error al Dar Formato a la clase:" + this.getClass());
		}
	}
	
	public int LongitudTrama(){
		
		int longitudTrama = 0;
		for(int i=0;i<lDeudaMultired.size();i++) {
			longitudTrama = longitudTrama
						+ ((DeudaMultired)lDeudaMultired.get(i)).LongitudTrama();
		}
		longitudTrama = longitudTrama + super.LongitudTrama();
		return longitudTrama;
	}
	

	public void FillBoby(String bodyOutPut,LDeudaMultired lDeuda1) throws Exception {
		
			initConsultaMultired();
			super.FillBoby(bodyOutPut);
			int longitudresult =bodyOutPut.length();
			int longitudDeudaMulti =super.LongitudTrama();
			
			
			int longDeuda = longitudDeudaMulti;
			
			for(int i=0;i<lDeuda1.size();i++) {

				int longDeudaMulti = ((DeudaMultired)lDeuda1.get(i)).LongitudTrama();
				
				if ( longitudresult >= longDeuda+longDeudaMulti){
					String BodyResult = bodyOutPut.substring(longDeuda
								,longDeuda+longDeudaMulti);
					//((Cheque)che.get(i)).FillBoby(BodyResult);
					DeudaMultired myDeuda = new NivelEndeudamiento();
					myDeuda.FillBoby(BodyResult);
					lDeudaMultired.add(myDeuda);
				}else{
					DeudaMultired myDeuda = null;
					lDeudaMultired.add(myDeuda);
				};
				longDeuda = longDeuda + longDeudaMulti;
			}
			
		}

	public String toString(){
		StringBuffer camposstring = new StringBuffer("");
		camposstring.append( super.toString() + separador);
		for(int i=0;i<lDeudaMultired.size();i++) {
			camposstring.append( ((DeudaMultired)lDeudaMultired.get(i)).toString() + separador);	
		}		
		return camposstring.toString();
	}

	public LDeudaMultired getLdeudaMultired() {
		return lDeudaMultired;
	}
}
